package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizDeliveryNote;
import com.ruoyi.system.service.IBizDeliveryNoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 送货单Controller
 * 
 * @author ruoyi
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/system/note")
public class BizDeliveryNoteController extends BaseController
{
    @Autowired
    private IBizDeliveryNoteService bizDeliveryNoteService;

    @Autowired
    private com.ruoyi.web.support.SupplierContext supplierContext;

    /**
     * 查询送货单列表
     */
    @PreAuthorize("@ss.hasPermi('system:note:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizDeliveryNote bizDeliveryNote)
    {
        supplierContext.resolveCurrentSupplierCode().ifPresent(bizDeliveryNote::setSupplierCode);
        startPage();
        List<BizDeliveryNote> list = bizDeliveryNoteService.selectBizDeliveryNoteList(bizDeliveryNote);
        return getDataTable(list);
    }

    /**
     * 导出送货单列表
     */
    @PreAuthorize("@ss.hasPermi('system:note:export')")
    @Log(title = "送货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDeliveryNote bizDeliveryNote)
    {
        supplierContext.resolveCurrentSupplierCode().ifPresent(bizDeliveryNote::setSupplierCode);
        List<BizDeliveryNote> list = bizDeliveryNoteService.selectBizDeliveryNoteList(bizDeliveryNote);
        ExcelUtil<BizDeliveryNote> util = new ExcelUtil<BizDeliveryNote>(BizDeliveryNote.class);
        util.exportExcel(response, list, "送货单数据");
    }

    /**
     * 获取送货单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:note:query')")
    @GetMapping(value = "/{deliveryNoteId}")
    public AjaxResult getInfo(@PathVariable("deliveryNoteId") Long deliveryNoteId)
    {
        return success(bizDeliveryNoteService.selectBizDeliveryNoteByDeliveryNoteId(deliveryNoteId));
    }

    /**
     * 新增送货单
     */
    @PreAuthorize("@ss.hasPermi('system:note:add')")
    @Log(title = "送货单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDeliveryNote bizDeliveryNote)
    {
        return toAjax(bizDeliveryNoteService.insertBizDeliveryNote(bizDeliveryNote));
    }

    /**
     * 修改送货单
     */
    @PreAuthorize("@ss.hasPermi('system:note:edit')")
    @Log(title = "送货单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDeliveryNote bizDeliveryNote)
    {
        return toAjax(bizDeliveryNoteService.updateBizDeliveryNote(bizDeliveryNote));
    }

    /**
     * 删除送货单
     */
    @PreAuthorize("@ss.hasPermi('system:note:remove')")
    @Log(title = "送货单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deliveryNoteIds}")
    public AjaxResult remove(@PathVariable Long[] deliveryNoteIds)
    {
        return toAjax(bizDeliveryNoteService.deleteBizDeliveryNoteByDeliveryNoteIds(deliveryNoteIds));
    }
}
